using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
using UnityEngine.Jobs;

namespace JobDemo
{
    [BurstCompile(CompileSynchronously = true)]
    public struct AddJob : IJob
    {
        public float a;
        public float b;
        public NativeArray<float> result;

        public void Execute()
        {
            result[0] = a + b;
        }
    }

    [BurstCompile(CompileSynchronously = true)]
    public struct IncreaseJob : IJob
    {
        public NativeArray<float> result;

        public void Execute()
        {
            result[0] += 1f;
        }
    }

    [BurstCompile(CompileSynchronously = true)]
    public struct ParallelAddJob : IJobParallelFor
    {
        [ReadOnly]
        public NativeArray<float> a;

        [ReadOnly]
        public NativeArray<float> b;

        public NativeArray<float> result;

        public void Execute(int index)
        {
            result[index] = a[index] + b[index];
        }
    }

    [BurstCompile(CompileSynchronously = true)]
    public struct TransformJob : IJobParallelForTransform
    {
        public float Speed;

        public void Execute(int index, TransformAccess trans)
        {
            trans.position = RotatePointAroundPivot(trans.position, Vector3.zero, Vector3.up * Speed);
        }

        public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
        {
            return Quaternion.Euler(angles) * (point - pivot) + pivot;
        }
    }
}